package com.li.mybatisconfig;

import com.alibaba.fastjson.JSON;
import com.li.mybatisconfig.config.MysqlSession;
import com.li.mybatisconfig.entity.User;
import com.li.mybatisconfig.mapper.UserMapper;
import org.junit.Test;

/**
 * @Description：
 * @Author：LiDong
 * @Create：2020/9/2
 * @Version：1.0.0
 */
public class MybatisTestRunner {

    MysqlSession mysqlSession=new MysqlSession();
    UserMapper mapper=mysqlSession.getMapper(UserMapper.class);

    @Test
    public void findById(){
        User user = mapper.selectById("1");
        System.out.println(user);
    }

    @Test
    public void insert(){
        User user=new User();
        user.setId(2);
        user.setUsername("test1");
        user.setPassword("test1");
        mapper.insert(JSON.toJSON(user));
    }

    @Test
    public void deleteById(){
        mapper.deleteById("1");
    }

    @Test
    public void update(){
        User user=new User();
        user.setId(2);
        user.setUsername("test2");
        user.setPassword("test2");
        mapper.updateById(JSON.toJSON(user));
    }


}
